<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="./Template/Template.xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions">

    <ui:define name="title">
        title
    </ui:define>

    <ui:define name="content">
        <h:form>
            <p:messages showDetail="true" showSummary="true"/>
            <p:outputPanel>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Name" />
                    <p:inputText value="#{employeesRESTBean.name}"
                                 required="true" requiredMessage="please enter name"/>
                    <h:outputLabel value="Country" />
                    <p:inputText value="#{employeesRESTBean.country}"
                                 required="true" requiredMessage="please enter country"/>

                    <h:outputLabel value="Birthday" />
                    <p:calendar value="#{employeesRESTBean.birthDay}"
                                required="true" requiredMessage="please enter birthday"
                                maxdate="#{employeesRESTBean.today}"
                                navigator="true" yearRange="c-30:c+30"
                                pattern="dd/MMM/yyyy"/>
                    <h:outputLabel value="Gender" />
                    <h:selectOneRadio value="#{employeesRESTBean.male}" required="true"
                                      requiredMessage="please enter gender">
                        <f:selectItem itemLabel="Male" itemValue="true"/>
                        <f:selectItem itemLabel="Female" itemValue="false"/>
                    </h:selectOneRadio>

                    <h:outputLabel/>
                    <h:panelGroup>
                        <p:commandButton value="Register" action="#{employeesRESTBean.register}"
                                         update="msg,msgs,emp"/>
                        <p:commandButton value="Reset" type="reset"/>
                    </h:panelGroup>
                </h:panelGrid>
            </p:outputPanel>
            <br></br>
            <p:dataTable value="#{employeesRESTBean.empList}"
                         var="emp"
                         paginator="true" rows="10"
                         style="text-align: center"
                         paginatorAlwaysVisible="false"
                         id="empTable">
                <f:facet name="header">
                    List of Employees
                </f:facet>

                <p:column sortBy="#{emp.name}" filterBy="#{emp.name}" filterMatchMode="contains">
                    <f:facet name="header">
                        Name
                    </f:facet>

                    <h:outputText value="#{emp.name}" />
                </p:column>

                <p:column headerText="Country" sortBy="#{emp.country}"
                          filterBy="#{emp.country}" filterMatchMode="contains">
                    <h:outputText value="#{emp.country}" />
                </p:column>

                <p:column headerText="Birtday" sortBy="#{emp.birthdayInDate}"
                          filterBy="#{emp.birthdayInString}" filterMatchMode="contains">
                    <h:outputText value="#{emp.birthdayInString}" />
                </p:column>

                <p:column headerText="Gender" sortBy="#{emp.gender}"
                          filterBy="#{emp.gender}" filterMatchMode="contains">
                    <h:outputText value="#{emp.gender}" />
                </p:column>

                <f:facet name="footer">
                    Total : #{fn:length(employeesRESTBean.empList)} employees
                </f:facet>
            </p:dataTable>
        </h:form>
    </ui:define>

</ui:composition>
